package com.xmindguoguo.boot.core.beetl;

import java.util.Objects;

import com.xmindguoguo.boot.modular.system.model.TSystemDeptModel;
import com.xmindguoguo.boot.modular.system.model.TSystemUserModel;
import com.xmindguoguo.boot.modular.system.service.ITSystemDeptService;
import com.xmindguoguo.boot.modular.system.service.ITSystemRoleService;
import com.xmindguoguo.boot.modular.system.service.ITSystemUserService;
import com.xmindguoguo.boot.util.spring.SpringContextHolder;

/**
 * 一些常用的关联查询 例如 根据保存的id查询用户名称之类的
 * 
 * @ClassName DBUtil
 * @author <a href="892042158@qq.com" target="_blank">于国帅</a>
 * @date 2019年2月15日 下午10:50:49
 *
 */
public class DBUtil {
    private ITSystemUserService systemUserService = SpringContextHolder.getBean(ITSystemUserService.class);
    private ITSystemRoleService systemRoleService = SpringContextHolder.getBean(ITSystemRoleService.class);
    private ITSystemDeptService systemDeptService = SpringContextHolder.getBean(ITSystemDeptService.class);

    public TSystemUserModel getUser(Long id) {
        TSystemUserModel model = null;
        if (Objects.nonNull(id)) {
            model = systemUserService.selectById(id);
        }
        if (model == null) { // 如果是空的 用model代替 防止出现异常
            model = new TSystemUserModel();
        }
        return model;
    }

    public TSystemDeptModel getDept(Long id) {
        TSystemDeptModel model = null;
        if (Objects.nonNull(id)) {
            model = systemDeptService.selectById(id);
        }
        if (model == null) { // 如果是空的 用model代替 防止出现异常
            model = new TSystemDeptModel();
        }
        return model;
    }

    public String getDeptName(Long id) {
        TSystemDeptModel model = null;
        if (Objects.nonNull(id)) {
            model = systemDeptService.selectById(id);
            return model.getFullName();
        }
        return "顶级";
    }
}
